package com.ys.ui
{
	import com.ys.obj.Text;
	import com.ys.util.Const;
	import com.ys.util.GraphicsUtil;
	
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	
	public class Button extends Sprite
	{
		public var textField:Text;
		
		public function Button(r:Number, color:uint, txt:String=null)
		{
			drawCircularButton(this, r, color);
			mouseChildren = false;
			useHandCursor = buttonMode = true;
			
			addChild( GraphicsUtil.drawCircularButton(r, color) );
			
			textField = new Text;
			textField.setProperties(12, 0xffffff)
			
			if (txt && txt != 'v:5')
			{
				textField.text = txt.toUpperCase();
			} else if (txt)
			{
				textField.text = txt;
			}
			textField.centerPosition();
			addChild(textField);
		}
		
		public static function drawCircularButton(spr:Sprite, r:Number, color:uint):void
		{
			spr.graphics.beginFill(color, 1);
			spr.graphics.drawCircle(0, 0, r/2);
			
			
			spr.addEventListener(MouseEvent.ROLL_OVER, onRollOver);
			spr.addEventListener(MouseEvent.ROLL_OUT, onRollOut);
			
			function onRollOver(e:MouseEvent):void
			{
				reset();
				spr.graphics.lineStyle(4, Const.HIGHIGHT_COLOR);
				spr.graphics.drawCircle(0, 0, r/2);
			}
			
			function onRollOut(e:MouseEvent):void
			{
				reset();
				spr.graphics.drawCircle(0, 0, r/2);
			}
			
			function reset():void
			{
				spr.graphics.clear();
				spr.graphics.beginFill(color, 1);
			}
		}
	}
}